package com.luobd.bpm.controller;


import com.luobd.bpm.business.user.service.IAuthService;
import com.luobd.bpm.common.Base64Captcha;
import com.luobd.bpm.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(tags = "用户登录认证模块")
@RequestMapping(value = "/api/auth")
public class AuthController {


    @Resource
    private IAuthService authService;




    @PostMapping(value = "/login")
    @ApiOperation(value = "登录认证")
    public ResponseData<String> login(@RequestBody LoginInput input){
        return authService.auth(input.getUsername(),input.getPassword());
    }

    @GetMapping(value = "/logout")
    @ApiOperation(value = "注销")
    public ResponseData<Boolean> logout(){
        return authService.logout();
    }


    @GetMapping(value = "/getCaptchaBase64")
    @ApiOperation(value = "获取验证码")
    public ResponseData<Base64Captcha> getCaptchaBase64() {
        return authService.getCaptchaBase64();
    }







}

@Data
@ApiModel(description = "登录输入参数")
class LoginInput {

    @ApiModelProperty(value = "用户名")
    private String username;

    @ApiModelProperty(value = "密码")
    private String password;

    @ApiModelProperty(value = "验证码")
    private String captcha;

    @ApiModelProperty(value = "验证码ID")
    private String captchaId;

}
